WPS Office.apk(点击下载) / gke.java


package defpackage;

import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import cn.wps.moffice.OfficeApp;
import cn.wps.moffice_eng.R;
import com.baidu.tts.loopj.AsyncHttpResponseHandler;
import com.iflytek.cloud.SpeechEvent;
import com.iflytek.cloud.SpeechUtility;
import defpackage.ghu;
import defpackage.ghz;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

/* renamed from: gke  reason: default package */
public class gke {
    private void a(List<ghu> list, String str, int i, int i2, String str2, boolean z) {
        if (list.size() > 0) {
            if (i == 1) {
                ghu ghu = new ghu();
                ghu.gEV = 2;
                ghu.extras = new ArrayList();
                ghu.extras.add(new ghu.a("keyword", str));
                ghu.extras.add(new ghu.a("template_type", Integer.valueOf(i2)));
                ghu.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i)));
                if (!(i == 2 && bPF() == 1 && !TextUtils.isEmpty(str2))) {
                    ghu.extras.add(new ghu.a("header", OfficeApp.arx().getString(R.string.name_templates)));
                }
                list.add(0, ghu);
            }
            if (i == 1) {
                ghu ghu2 = new ghu();
                ghu2.gEV = 3;
                ghu2.extras = new ArrayList();
                ghu2.extras.add(new ghu.a("keyword", str));
                ghu2.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i)));
                if (z) {
                    ghu2.extras.add(new ghu.a("bottom", OfficeApp.arx().getString(R.string.phone_home_new_search_more_template)));
                }
                ghu2.extras.add(new ghu.a("jump", "jump_model"));
                list.add(ghu2);
            }
        }
    }

    private String b(String str, String str2, String str3, int i, int i2, int i3, gic gic) {
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("http://docer.wps.cn/v3.php/api/search/filter/keyword?keyword=");
            try {
                sb.append(URLEncoder.encode(str, AsyncHttpResponseHandler.DEFAULT_CHARSET));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            HashMap hashMap = new HashMap();
            hashMap.put("mb_platform", "16");
            hashMap.put("del_img_scale", "1");
            hashMap.put("file_type", "1");
            hashMap.put("mb_app", String.valueOf(i2));
            if (i3 != 0) {
                hashMap.put("mb_type", String.valueOf(i3));
            }
            if (!TextUtils.isEmpty(str2)) {
                hashMap.put("orderby", str2);
            }
            if (!TextUtils.isEmpty(str3)) {
                hashMap.put("order_direction", str3);
            }
            if (i == 1) {
                hashMap.put("page", "1");
                hashMap.put("per_page", "4");
            } else {
                hashMap.put("page", new StringBuilder().append(bPF()).toString());
                hashMap.put("per_page", "10");
            }
            if (gic != null && gic.aLi()) {
                if (!TextUtils.isEmpty(gic.hcn)) {
                    hashMap.put("mb_app", gic.hcn);
                } else {
                    hashMap.put("mb_app", "0");
                }
                if (!TextUtils.isEmpty(gic.tags)) {
                    hashMap.put("tags", gic.tags);
                }
                if (!TextUtils.isEmpty(gic.hcp)) {
                    hashMap.put("price_max", gic.hcp);
                }
                if (!TextUtils.isEmpty(gic.hco)) {
                    hashMap.put("price_min", gic.hco);
                }
            }
            for (Map.Entry entry : hashMap.entrySet()) {
                sb.append('&');
                sb.append((String) entry.getKey());
                sb.append('=');
                sb.append((String) entry.getValue());
            }
            return lwd.f(sb.toString(), null);
        } catch (IOException e2) {
            e2.printStackTrace();
            return "";
        }
    }

    private String c(String str, String str2, String str3, int i, int i2, int i3) {
        try {
            StringBuilder sb = new StringBuilder();
            sb.append("http://docer.wps.cn/v3.php/api/search/range/keyword?keyword=");
            try {
                sb.append(URLEncoder.encode(str, AsyncHttpResponseHandler.DEFAULT_CHARSET));
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            HashMap hashMap = new HashMap();
            hashMap.put("mb_platform", "16");
            hashMap.put("del_img_scale", "1");
            hashMap.put("file_type", "1");
            hashMap.put("mb_app", String.valueOf(i2));
            if (i3 != 0) {
                hashMap.put("mb_type", String.valueOf(i3));
            }
            if (!TextUtils.isEmpty(str2)) {
                hashMap.put("orderby", str2);
            }
            if (!TextUtils.isEmpty(str3)) {
                hashMap.put("order_direction", str3);
            }
            if (i == 1) {
                hashMap.put("page", "1");
                hashMap.put("per_page", "4");
            } else {
                hashMap.put("page", new StringBuilder().append(bPF()).toString());
                hashMap.put("per_page", "10");
            }
            for (Map.Entry entry : hashMap.entrySet()) {
                sb.append('&');
                sb.append((String) entry.getKey());
                sb.append('=');
                sb.append((String) entry.getValue());
            }
            return lwd.f(sb.toString(), null);
        } catch (IOException e2) {
            e2.printStackTrace();
            return "";
        }
    }

    private List<dts> h(JSONObject jSONObject) {
        JSONObject jSONObject2;
        dts[] dtsArr;
        try {
            if (!(!k(jSONObject) || (jSONObject2 = jSONObject.getJSONObject(SpeechEvent.KEY_EVENT_RECORD_DATA)) == null || (dtsArr = (dts[]) lvb.b(jSONObject2.getString(SpeechEvent.KEY_EVENT_RECORD_DATA), dts[].class)) == null)) {
                ArrayList arrayList = new ArrayList();
                for (dts dts : dtsArr) {
                    arrayList.add(dts);
                }
                return arrayList;
            }
        } catch (JSONException e) {
        }
        return null;
    }

    private ghz i(JSONObject jSONObject) {
        JSONObject jSONObject2;
        try {
            if (k(jSONObject) && (jSONObject2 = jSONObject.getJSONObject(SpeechEvent.KEY_EVENT_RECORD_DATA)) != null) {
                ghz ghz = new ghz();
                ghz.a[] aVarArr = (ghz.a[]) lvb.b(jSONObject2.getJSONObject("aggs").getString("filter_array"), ghz.a[].class);
                if (aVarArr != null) {
                    ghz.hci = Arrays.asList(aVarArr);
                }
                return ghz;
            }
        } catch (JSONException e) {
        }
        return null;
    }

    private String j(JSONObject jSONObject) {
        try {
            return k(jSONObject) ? jSONObject.getJSONObject(SpeechEvent.KEY_EVENT_RECORD_DATA).getString("total_num") : "";
        } catch (Exception e) {
            return "";
        }
    }

    private static boolean k(JSONObject jSONObject) {
        if (jSONObject != null) {
            try {
                return "ok".equals(jSONObject.get(SpeechUtility.TAG_RESOURCE_RESULT)) && jSONObject.has(SpeechEvent.KEY_EVENT_RECORD_DATA);
            } catch (JSONException e) {
            }
        }
    }

    public final List<ghu> a(String str, String str2, String str3, int i, int i2, int i3) {
        try {
            ArrayList arrayList = new ArrayList();
            JSONObject jSONObject = new JSONObject(c(str, str2, str3, i, i2, i3));
            List<dts> h = h(jSONObject);
            gnb.bB(h);
            String j = j(jSONObject);
            if (h == null || h.size() <= 0) {
                return arrayList;
            }
            boolean z = false;
            if (i == 1 && h.size() > 3) {
                z = true;
                h.remove(h.size() - 1);
            }
            int i4 = 0;
            while (i4 < h.size() && (i == 2 || (i == 1 && i4 < 3))) {
                ghu ghu = new ghu();
                ghu.gEV = 1;
                ghu.hbW = j;
                ghu.extras = new ArrayList();
                ghu.extras.add(new ghu.a("object", h.get(i4)));
                ghu.extras.add(new ghu.a("keyword", str));
                ghu.extras.add(new ghu.a("template_type", Integer.valueOf(i2)));
                ghu.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i)));
                ghu.extras.add(new ghu.a("order_by", str2));
                ghu.extras.add(new ghu.a("order_direction", str3));
                arrayList.add(ghu);
                i4++;
            }
            a(arrayList, str, i, i2, j, z);
            return arrayList;
        } catch (Exception e) {
            return null;
        }
    }

    public final List<ghu> a(String str, String str2, String str3, int i, int i2, int i3, gic gic) {
        try {
            ArrayList arrayList = new ArrayList();
            JSONObject jSONObject = new JSONObject(b(str, str2, str3, i, i2, i3, gic));
            List<dts> h = h(jSONObject);
            gnb.bB(h);
            String j = j(jSONObject);
            if (h == null || h.size() <= 0) {
                return arrayList;
            }
            boolean z = false;
            if (i == 1 && h.size() > 3) {
                z = true;
                h.remove(h.size() - 1);
            }
            int i4 = 0;
            while (i4 < h.size() && (i == 2 || (i == 1 && i4 < 3))) {
                ghu ghu = new ghu();
                ghu.gEV = 1;
                ghu.hbW = j;
                ghu.extras = new ArrayList();
                ghu.extras.add(new ghu.a("object", h.get(i4)));
                ghu.extras.add(new ghu.a("keyword", str));
                ghu.extras.add(new ghu.a("template_type", Integer.valueOf(i2)));
                ghu.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i)));
                ghu.extras.add(new ghu.a("order_by", str2));
                ghu.extras.add(new ghu.a("order_direction", str3));
                arrayList.add(ghu);
                i4++;
            }
            a(arrayList, str, i, i2, j, z);
            return arrayList;
        } catch (Exception e) {
            return null;
        }
    }

    public final gia b(String str, String str2, String str3, int i, int i2, int i3) {
        try {
            ArrayList arrayList = new ArrayList();
            JSONObject jSONObject = new JSONObject(c(str, str2, str3, i, i2, i3));
            List<dts> h = h(jSONObject);
            gnb.bB(h);
            String j = j(jSONObject);
            ghz i4 = i(jSONObject);
            if (h != null && h.size() > 0) {
                boolean z = false;
                if (i == 1 && h.size() > 3) {
                    z = true;
                    h.remove(h.size() - 1);
                }
                int i5 = 0;
                while (i5 < h.size() && (i == 2 || (i == 1 && i5 < 3))) {
                    ghu ghu = new ghu();
                    ghu.gEV = 1;
                    ghu.hbW = j;
                    ghu.extras = new ArrayList();
                    ghu.extras.add(new ghu.a("object", h.get(i5)));
                    ghu.extras.add(new ghu.a("keyword", str));
                    ghu.extras.add(new ghu.a("template_type", Integer.valueOf(i2)));
                    ghu.extras.add(new ghu.a(NotificationCompat.CATEGORY_STATUS, Integer.valueOf(i)));
                    ghu.extras.add(new ghu.a("order_by", str2));
                    ghu.extras.add(new ghu.a("order_direction", str3));
                    arrayList.add(ghu);
                    i5++;
                }
                a(arrayList, str, i, i2, j, z);
            }
            gia gia = new gia();
            gia.axC = arrayList;
            gia.hcm = i4;
            return gia;
        } catch (Exception e) {
            return null;
        }
    }

    public int bPF() {
        return 1;
    }
}